const mysql = require('../db/mysql57');

const loginDao = {
    // 小程序登录
    loginByOpenid(openid) {
        let sql = `select * from User where openid = ? LIMIT 1`;
        let data = [ openid ];
        return mysql.sqlExec(sql, data);
    },
    // 小程序注册
    addUser(openid) {
        let sql = `INSERT INTO User (userTypeId, openid, username, sex, grade, college, subCollege, major) VALUES (
            (
                select id from UserType where name = ? LIMIT 1
            ), ?, ?, ?, ?, ?, ?, ?)`;
        let data = [ 'user', openid, '*', '男', '大一', '*', '*', '*' ];
        return mysql.sqlExec(sql, data);
    }
};

module.exports = loginDao;